﻿using System;
using System.Globalization;

namespace Twitter
{
	internal static class Timestamp
	{
		// Parse Twitter weird format.
		// See http://groups.google.com/group/twitter-development-talk/browse_thread/thread/a976b23542669589/61897c7deef8c723?lnk=gst&q=created_at+date+format#61897c7deef8c723
		// http://groups.google.com/group/twitter-development-talk/browse_thread/thread/71752b5ff24385e7/6abec8f29513f7b6?lnk=gst&q=created_at+date+format#6abec8f29513f7b6
		public static DateTime? Parse(string twitterTimestamp)
		{
			DateTime? value = null;
			DateTime parsed;
			if (DateTime.TryParseExact(twitterTimestamp,
				"ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture,
				DateTimeStyles.AdjustToUniversal, out parsed))
			{
				value = parsed;
			}

			return value;
		}
	}
}
